package com.example.base.ext

import com.example.base.bean.ApiException
import com.example.base.base.bean.BaseBean
import com.example.base.bean.ResponseResult
import com.example.base.base.viewmodel.BaseRepository

/**
 * @Description
 * @department 城市元宇宙组
 * @Author niushilong
 * @Date 2024-04-05 16:29
 */
suspend fun<T> BaseRepository.extRequestHttp(call: suspend () -> BaseBean<T>): ResponseResult<T> {

    return try {
        val response = call()
        if (response.code == 1){
            // 成功
            ResponseResult.Success(response.data)
        }else{
            ResponseResult.Error(ApiException(response.code, response.message))
        }
    }catch (e: Exception){
        e.printStackTrace()
        ResponseResult.Error(handleExceptionMessage(e))
    }
}